<?php

class Login extends Controller
{
	var $data=array();
	
	public function __construct()
	{
		parent::Controller();	

		$this->load->model('Login_Model');
		$this->data['username']='';
		$this->data['password']='';
		$this->data['warning']='';
	}
	
	function index()
	{
		if($this->input->post('submit'))
		{
			$this->data['username']=trim($this->input->post('username'));
			$this->data['password']=trim($this->input->post('password'));

			if($this->input->post('submit'))
			{
				if(strcmp($this->data['username'], '')==0)
				{
					$this->data['warning']="Username was not entered. <br />\n";
				}
				else if(strcmp($this->data['password'], '')==0)
				{
					$this->data['warning']="Password was not entered. <br />\n";
				}
				else 
				{
					$result=$this->Login_Model->login_check($this->data['username'], $this->data['password']);
//					echo "Being Processed!";

					if($result==-1)
					{
						$this->data['warning']="Password or Username entered was Incorrect. <br />\n";
					}
					else
					{
						//login to the admin portal
						echo "login success!";
					}
				}
			}
			
		}
		
		// pases the information of the data to the view
		$this->load->view("login",$this->data);
	}
}
?>